<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Franchises extends Admin_Controller{

    function Franchises(){
        parent::Admin_Controller();
        $CI = & get_instance();
        $CI->load->module_model('franchises.franchise_model');

    }

    function edit(){
        $CI = & get_instance();
        $this->module_navigation('Manage Franchise');
        $CI->load->module_language('franchises.franchise_model');
        //$address_id = $CI->uri->segment(3);
        $address_id = 1;
        $CI->franchise_model->set_id($address_id);
        if(!$franchises = $CI->franchise_model->get_franchise($address_id)){
            set_flash_message(lang('franchise_edit_not_found'));
            redirect('admin/home');
        }

        $CI->load->library('form_validation');
        $CI->load->helper('form');
        $CI->form_validation->set_rules('address1', 'Address1', 'trim|required');
        $CI->form_validation->set_rules('city', 'city', 'trim|required');
        $CI->form_validation->set_rules('postcode', 'postcode', 'trim|required');
        $CI->form_validation->set_rules('state', 'state', 'trim|required');
        $CI->form_validation->set_rules('phone', 'phone', 'trim|required');    

        if ($CI->form_validation->run() !== FALSE){
            $data = array(
                          ADDRESS_LINE1 => $CI->input->post('address1'),
                          ADDRESS_LINE2 => $CI->input->post('address2'),
                          ADDRESS_LINE3 => $CI->input->post('address3'),
                          ADDRESS_CITY => $CI->input->post('city'),
                          ADDRESS_POSTCODE => $CI->input->post('postcode'),
                          ADDRESS_STATE => $CI->input->post('state'),
                          ADDRESS_PHONE => $CI->input->post('phone'),
                          ADDRESS_MOBILE => $CI->input->post('mobile'),
                          ADDRESS_FAX => $CI->input->post('fax'),
                          ADDRESS_EMAIL => $CI->input->post('email')
                          );

            if($CI->franchise_model->save_by_fid($data)){
                set_flash_message(lang('address_edit_success'));
                redirect('admin/home');
            }

        }
        $this->add('franchises', $franchises[0]);
        $this->module_tabbar('franchises.tab', array('active_tab'=>''));
        $this->view('add_new');
    }
}